package cn.broadmax.boot.modules.aj.controller;

import cn.broadmax.boot.base.SuperController;
import cn.broadmax.boot.base.message.SResult;
import cn.broadmax.boot.modules.aj.bean.ajManagePageSearch;
import cn.broadmax.boot.modules.aj.bean.showSearch;
import cn.broadmax.boot.modules.aj.entity.JzManage;
import cn.broadmax.boot.modules.aj.entity.Record;
import cn.broadmax.boot.modules.aj.mapper.JzManageMapper;
import cn.broadmax.boot.modules.aj.mapper.RecordMapper;
import cn.broadmax.boot.modules.aj.service.IRecordService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jexx.util.Console;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 可视化页面 前端控制器
 * </p>
 *
 * @author jexx
 * @since 2021-06-01
 */
@Api(tags = "可视化页面")
@RestController
@RequestMapping("/show")
@RequiredArgsConstructor
public class ShowController extends SuperController{
    @Autowired
    private final IRecordService iRecordService;

    @Autowired
    private final RecordMapper recordMapper;

    @Autowired
    private JzManageMapper jzManageMapper;

    @ApiOperation("案卷记录总数")
    @GetMapping(value = "/ajTotal")
    public SResult<Integer> ajTotalNum(){
        List<Record> records = recordMapper.selectList(null);
        return SResult.ok("",records.size());
    }

    @ApiOperation("卷宗记录总数")
    @GetMapping(value = "jzTotal")
    public SResult<Integer> jzTotalNum(){
        List<JzManage> jzManages = jzManageMapper.selectList(null);
        return SResult.ok("",jzManages.size());
    }

    @ApiOperation("各部门案件统计")
    @GetMapping(value = "/ajStat")
    public SResult<List<Integer>> ajStat(){
        ArrayList<String> areaList = new ArrayList<>();
        areaList.add("徐汇区");
        areaList.add("闵行区");
        areaList.add("杨浦区");
        areaList.add("青浦区");
        areaList.add("崇明区");
        areaList.add("金山区");
        ArrayList<Integer> list = new ArrayList<>();

        for (String area : areaList) {
            list.add(singleAreaNum(area));
//            Console.log(list.toString());
        }
        return SResult.ok("",list);
    }
//    单个地区案件统计数目(方法抽取)
    public Integer singleAreaNum(String areaNum){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("department",areaNum);
        return recordMapper.selectList(wrapper).size();
    }

    @ApiOperation("各部门已创建/未制作统计")
    @GetMapping(value = "/readyCreate")
    public SResult<List<Integer>> ajStatReadyCreate(){
        ArrayList<String> areaList = new ArrayList<>();
        areaList.add("徐汇区");
        areaList.add("闵行区");
        areaList.add("杨浦区");
        areaList.add("青浦区");
        areaList.add("崇明区");
        areaList.add("金山区");
        ArrayList<Integer> list = new ArrayList<>();

        for (String area : areaList) {
            list.add(singleAreaReadyNum(area));
//            Console.log(list.toString());
        }
        return SResult.ok("",list);
    }
    //    单个地区案件统计数目(方法抽取)
    public Integer singleAreaReadyNum(String areaNum){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("apply_unit",areaNum);
        return jzManageMapper.selectList(wrapper).size();
    }


}
